package datasource_bak

import (
	"gitee.com/kristas/booting-go/framework/core/configure"
)

type Helper struct {
	tag    string
	prefix string
}

func NewHelper() *Helper {
	return &Helper{
		tag:    "datasource",
		prefix: "application.datasource",
	}
}

func (d *Helper) SetPropertiesPrefix(prefix string) *Helper {
	d.prefix = prefix
	return d
}

func (d *Helper) SetDatasourceTag(datasource string) *Helper {
	d.tag = datasource
	return d
}

func (d *Helper) CreateDatasource() (Datasource, error) {
	conf := &Config{prefix: d.prefix}
	err := configure.BindConfiguration(conf)
	if err != nil {
		return nil, err
	}
	return &defaultDatasource{
		tag:  d.tag,
		conf: conf,
	}, nil
}

type defaultDatasource struct {
	tag  string
	conf *Config
}

func (d *defaultDatasource) Init() error {
	return nil
}

func (d *defaultDatasource) Destroy() error {
	return nil
}

func (d *defaultDatasource) Bean() string {
	return d.tag
}

func (d *defaultDatasource) Tag() string {
	return d.tag
}

func (d *defaultDatasource) GetType() string {
	return d.conf.Type
}

func (d *defaultDatasource) GetHost() string {
	return d.conf.Host
}

func (d *defaultDatasource) GetDatabase() string {
	return d.conf.Database
}

func (d *defaultDatasource) GetUsername() string {
	return d.conf.Username
}

func (d *defaultDatasource) GetPassword() string {
	return d.conf.Password
}

func (d *defaultDatasource) GetTunnel() string {
	return d.conf.Tunnel
}

func (d *defaultDatasource) GetConnMaxLifeTime() int64 {
	return d.conf.ConnMaxLifeTime
}

func (d *defaultDatasource) GetConnMaxIdleTime() int64 {
	return d.conf.ConnMaxIdleTime
}

func (d *defaultDatasource) GetMaxIdleConns() int {
	return d.conf.MaxIdleConns
}

func (d *defaultDatasource) GetMaxOpenConns() int {
	return d.conf.MaxOpenConns
}

func (d *defaultDatasource) IsLazyFetch() bool {
	return d.conf.LazyFetch
}
